package com.example.demo.day0301;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class BufferedOutput {
    public static void main(String[] args) {
        try {
            BufferedOutput.testBufferedOutputStream();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void testBufferedOutputStream() throws Exception {
        FileOutputStream out = new FileOutputStream("D:\\demo\\src\\main\\java\\com\\example\\demo\\day0301\\tt1.txt");
        //创建字节输出流对象

        BufferedOutputStream bo = new BufferedOutputStream(out);
        //将字节输出流对象放至缓冲字节输入流中

        String s = "hello world";

        bo.write(s.getBytes());//将数据写至内存中

        bo.flush();//将数据从内存刷至硬盘上

        bo.close();

        out.close();//先开后关
    }
}
